CREATE TABLE  "HTMLDB_PLAN_TABLE" 
   (	"STATEMENT_ID" VARCHAR2(30), 
	"PLAN_ID" NUMBER, 
	"TIMESTAMP" DATE, 
	"REMARKS" VARCHAR2(4000), 
	"OPERATION" VARCHAR2(30), 
	"OPTIONS" VARCHAR2(255), 
	"OBJECT_NODE" VARCHAR2(128), 
	"OBJECT_OWNER" VARCHAR2(30), 
	"OBJECT_NAME" VARCHAR2(30), 
	"OBJECT_ALIAS" VARCHAR2(65), 
	"OBJECT_INSTANCE" NUMBER(*,0), 
	"OBJECT_TYPE" VARCHAR2(30), 
	"OPTIMIZER" VARCHAR2(255), 
	"SEARCH_COLUMNS" NUMBER, 
	"ID" NUMBER(*,0), 
	"PARENT_ID" NUMBER(*,0), 
	"DEPTH" NUMBER(*,0), 
	"POSITION" NUMBER(*,0), 
	"COST" NUMBER(*,0), 
	"CARDINALITY" NUMBER(*,0), 
	"BYTES" NUMBER(*,0), 
	"OTHER_TAG" VARCHAR2(255), 
	"PARTITION_START" VARCHAR2(255), 
	"PARTITION_STOP" VARCHAR2(255), 
	"PARTITION_ID" NUMBER(*,0), 
	"OTHER" LONG, 
	"DISTRIBUTION" VARCHAR2(30), 
	"CPU_COST" NUMBER(*,0), 
	"IO_COST" NUMBER(*,0), 
	"TEMP_SPACE" NUMBER(*,0), 
	"ACCESS_PREDICATES" VARCHAR2(4000), 
	"FILTER_PREDICATES" VARCHAR2(4000), 
	"PROJECTION" VARCHAR2(4000), 
	"TIME" NUMBER(*,0), 
	"QBLOCK_NAME" VARCHAR2(30)
   )
/
CREATE TABLE  "TBL_ENDERECO" 
   (	"COD_ENDERECO" NUMBER(8,0) NOT NULL ENABLE, 
	"RUA" VARCHAR2(40), 
	"NUMERO" NUMBER(6,0), 
	"BAIRRO" VARCHAR2(30), 
	"CIDADE" VARCHAR2(30), 
	"CEP" VARCHAR2(8), 
	"UF" VARCHAR2(2), 
	"TELEFONE" VARCHAR2(20), 
	 CONSTRAINT "TBL_ENDERECO_PK" PRIMARY KEY ("COD_ENDERECO") ENABLE
   )
/
CREATE TABLE  "TBL_AUTOR" 
   (	"COD_AUTOR" NUMBER(8,0), 
	"COD_ENDERECO" NUMBER(8,0), 
	"IDENTIDADE" VARCHAR2(15), 
	"NOME" VARCHAR2(40), 
	 CONSTRAINT "TBL_AUTOR_PK" PRIMARY KEY ("COD_AUTOR") ENABLE, 
	 CONSTRAINT "TBL_AUTOR_FK" FOREIGN KEY ("COD_ENDERECO")
	  REFERENCES  "TBL_ENDERECO" ("COD_ENDERECO") ENABLE
   )
/
CREATE TABLE  "TBL_EDITORA" 
   (	"COD_EDITORA" NUMBER(8,0), 
	"COD_ENDERECO" NUMBER(8,0), 
	"NOME" VARCHAR2(40), 
	 CONSTRAINT "TBL_EDITORA_PK" PRIMARY KEY ("COD_EDITORA") ENABLE, 
	 CONSTRAINT "TBL_EDITORA_FK" FOREIGN KEY ("COD_ENDERECO")
	  REFERENCES  "TBL_ENDERECO" ("COD_ENDERECO") ENABLE
   )
/
CREATE TABLE  "TBL_GRAFICA" 
   (	"COD_GRAFICA" NUMBER(8,0), 
	"COD_ENDERECO" NUMBER(8,0), 
	"TIPO" CHAR(1), 
	"NOME" VARCHAR2(40), 
	"PROD_MAX_DIA" NUMBER(10,0), 
	"RESPONSAVEL" VARCHAR2(40), 
	 CONSTRAINT "TBL_GRAFICA_PK" PRIMARY KEY ("COD_GRAFICA") ENABLE, 
	 CONSTRAINT "TBL_GRAFICA_FK" FOREIGN KEY ("COD_ENDERECO")
	  REFERENCES  "TBL_ENDERECO" ("COD_ENDERECO") ENABLE
   )
/
CREATE TABLE  "TBL_LIVRO" 
   (	"ISBN" VARCHAR2(20), 
	"COD_EDITORA" NUMBER(8,0), 
	"TITULO" VARCHAR2(50), 
	"DT_PUBLICACAO" DATE, 
	 CONSTRAINT "TBL_LIVRO_PK" PRIMARY KEY ("ISBN") ENABLE, 
	 CONSTRAINT "TBL_LIVRO_FK" FOREIGN KEY ("COD_EDITORA")
	  REFERENCES  "TBL_EDITORA" ("COD_EDITORA") ENABLE
   )
/
CREATE TABLE  "TBL_LIVRO_AUTOR" 
   (	"ISBN" VARCHAR2(20), 
	"COD_AUTOR" NUMBER(8,0), 
	 CONSTRAINT "TBL_LIVRO_AUTOR_PK" PRIMARY KEY ("ISBN", "COD_AUTOR") ENABLE, 
	 CONSTRAINT "TBL_LIVRO_AUTOR_FK" FOREIGN KEY ("ISBN")
	  REFERENCES  "TBL_LIVRO" ("ISBN") ENABLE, 
	 CONSTRAINT "TBL_LIVRO_AUTOR_FK2" FOREIGN KEY ("COD_AUTOR")
	  REFERENCES  "TBL_AUTOR" ("COD_AUTOR") ENABLE
   )
/
CREATE TABLE  "TBL_PEDIDO" 
   (	"COD_PEDIDO" NUMBER(8,0), 
	"COD_GRAFICA" NUMBER(8,0), 
	"ISBN" VARCHAR2(20), 
	"DT_PEDIDO" DATE, 
	"QTDE_COPIAS" NUMBER(8,0), 
	"VALOR" NUMBER(14,2), 
	"DT_ENTREGA" DATE, 
	"SITUACAO" CHAR(1), 
	 CONSTRAINT "TBL_PEDIDO_PK" PRIMARY KEY ("COD_PEDIDO") ENABLE, 
	 CONSTRAINT "TBL_PEDIDO_FK" FOREIGN KEY ("COD_GRAFICA")
	  REFERENCES  "TBL_GRAFICA" ("COD_GRAFICA") ENABLE, 
	 CONSTRAINT "TBL_PEDIDO_FK2" FOREIGN KEY ("ISBN")
	  REFERENCES  "TBL_LIVRO" ("ISBN") ENABLE
   )
/
CREATE TABLE  "TBL_PEDIDO_GRAFICA" 
   (	"COD_PEDIDO" NUMBER(8,0) NOT NULL ENABLE, 
	"COD_GRAFICA" NUMBER(8,0) NOT NULL ENABLE, 
	"PEDIDO_QTDE" NUMBER(10,0), 
	"VALOR" NUMBER(14,2), 
	"CONTRATO" VARCHAR2(20), 
	 CONSTRAINT "TBL_PEDIDO_GRAFICA_PK" PRIMARY KEY ("COD_PEDIDO", "COD_GRAFICA") ENABLE, 
	 CONSTRAINT "TBL_PEDIDO_GRAFICA_FK" FOREIGN KEY ("COD_PEDIDO")
	  REFERENCES  "TBL_PEDIDO" ("COD_PEDIDO") ENABLE, 
	 CONSTRAINT "TBL_PEDIDO_GRAFICA_FK2" FOREIGN KEY ("COD_GRAFICA")
	  REFERENCES  "TBL_GRAFICA" ("COD_GRAFICA") ENABLE
   )
/
CREATE UNIQUE INDEX  "TBL_PEDIDO_PK" ON  "TBL_PEDIDO" ("COD_PEDIDO")
/
CREATE UNIQUE INDEX  "TBL_PEDIDO_GRAFICA_PK" ON  "TBL_PEDIDO_GRAFICA" ("COD_PEDIDO", "COD_GRAFICA")
/
CREATE UNIQUE INDEX  "TBL_LIVRO_PK" ON  "TBL_LIVRO" ("ISBN")
/
CREATE UNIQUE INDEX  "TBL_LIVRO_AUTOR_PK" ON  "TBL_LIVRO_AUTOR" ("ISBN", "COD_AUTOR")
/
CREATE UNIQUE INDEX  "TBL_GRAFICA_PK" ON  "TBL_GRAFICA" ("COD_GRAFICA")
/
CREATE UNIQUE INDEX  "TBL_ENDERECO_PK" ON  "TBL_ENDERECO" ("COD_ENDERECO")
/
CREATE UNIQUE INDEX  "TBL_EDITORA_PK" ON  "TBL_EDITORA" ("COD_EDITORA")
/
CREATE UNIQUE INDEX  "TBL_AUTOR_PK" ON  "TBL_AUTOR" ("COD_AUTOR")
/
 CREATE SEQUENCE   "TBL_PEDIDO_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE
/
 CREATE SEQUENCE   "TBL_GRAFICA_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE
/
 CREATE SEQUENCE   "TBL_ENDERECO_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 41 CACHE 20 NOORDER  NOCYCLE
/
 CREATE SEQUENCE   "TBL_EDITORA_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE
/
 CREATE SEQUENCE   "TBL_AUTOR_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE
/
 CREATE SEQUENCE   "RUA_LOOKUP_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER  NOCYCLE
/
CREATE OR REPLACE TRIGGER  "BI_TBL_PEDIDO" 
  before insert on "TBL_PEDIDO"               
  for each row  
begin   
    select "TBL_PEDIDO_SEQ".nextval into :NEW.COD_PEDIDO from dual; 
end; 

/
ALTER TRIGGER  "BI_TBL_PEDIDO" ENABLE
/
CREATE OR REPLACE TRIGGER  "BI_TBL_GRAFICA" 
  before insert on "TBL_GRAFICA"               
  for each row  
begin   
    select "TBL_GRAFICA_SEQ".nextval into :NEW.COD_GRAFICA from dual; 
end; 

/
ALTER TRIGGER  "BI_TBL_GRAFICA" ENABLE
/
CREATE OR REPLACE TRIGGER  "BI_TBL_ENDERECO" 
  before insert on "TBL_ENDERECO"               
  for each row  
begin   
    select "TBL_ENDERECO_SEQ".nextval into :NEW.COD_ENDERECO from dual; 
end; 

/
ALTER TRIGGER  "BI_TBL_ENDERECO" ENABLE
/
CREATE OR REPLACE TRIGGER  "BI_TBL_EDITORA" 
  before insert on "TBL_EDITORA"               
  for each row  
begin   
    select "TBL_EDITORA_SEQ".nextval into :NEW.COD_EDITORA from dual; 
end; 

/
ALTER TRIGGER  "BI_TBL_EDITORA" ENABLE
/
CREATE OR REPLACE TRIGGER  "BI_TBL_AUTOR" 
  before insert on "TBL_AUTOR"               
  for each row  
begin   
    select "TBL_AUTOR_SEQ".nextval into :NEW.COD_AUTOR from dual; 
end; 

/
ALTER TRIGGER  "BI_TBL_AUTOR" ENABLE
/